#include "Nuclear.h"

GLfloat nuclear_diffuse[] = {0.7, 0.7, 0.7, 1.0};
GLfloat nuclear_ambient[] = {0.7, 0.7, 0.7, 1.0};
GLfloat nuclear_specular[] = {0.5, 0.5, 0.5, 1.0};

// Shininess
GLfloat nuclear_shininess = 10.0f;

Nuclear::Nuclear()
{
	// UPGRADES
	upgradeLife = 1;
	upgradePower = 5;

	outerRadius = (GLfloat)1;
	innerRadius = (GLfloat)0.95;
	innerMostRadius = (GLfloat)1/5;
	height = (GLfloat) 1/2;
	quad = gluNewQuadric();
	loadImage();
}

int Nuclear::getUpgradeLife()
{
	return upgradeLife;
}

int Nuclear::getUpgradePower()
{
	return upgradePower;
}

void Nuclear::loadImage()
{
	Image* image1 = loadBMP("textures\\alu.bmp");
	Image* image2 = loadBMP("textures\\copper.bmp");
	Image* image3 = loadBMP("textures\\nuclearSign.bmp");
	Image* image4 = loadBMP("textures\\nuclearSign2.bmp");
	textureBase1 = loadTexture(image1);
	textureBase2 = loadTexture(image2);
	textureNuclear1 = loadTexture(image3);
	textureNuclear2 = loadTexture(image4);
	
	currentTextureBase = textureBase1;
	currentTextureNuclear = textureNuclear1;

	delete image1;
	delete image2;
	delete image3;
	delete image4;
}

void Nuclear::switchTexture()
{
	if(currentTextureBase == textureBase1)
		currentTextureBase = textureBase2;
	else
		currentTextureBase = textureBase1;
	if(currentTextureNuclear == textureNuclear1)
		currentTextureNuclear = textureNuclear2;
	else
		currentTextureNuclear = textureNuclear1;
}

void Nuclear::display()
{
	glPushMatrix();
		glTranslatef(0.0, elevation, 0.0);

		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, nuclear_diffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, nuclear_ambient );
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, nuclear_specular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, nuclear_shininess);
		glColor3f(1,1,1);
		glScalef((GLfloat)1/2, (GLfloat)1/2, (GLfloat)1/2);
		
		gluQuadricNormals(quad, GLU_SMOOTH);   // Create Smooth Normals (better for light)
		gluQuadricTexture(quad, GL_TRUE);      // Create Texture Coords
		
		// base and bottom
		glPushMatrix();
			glBindTexture(GL_TEXTURE_2D, currentTextureBase);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			
			glRotatef(-90, 1.0, 0.0, 0.0);
			gluCylinder (quad, outerRadius, outerRadius, height, 30.0, 3.0);
		glPopMatrix();

		glPushMatrix();
			glRotatef(-90, 1.0, 0.0, 0.0);
			gluDisk(quad, 0.0, outerRadius, 30.0, 3.0);
		glPopMatrix();
		
		// nuclear picture
		glPushMatrix();
			glBindTexture(GL_TEXTURE_2D, currentTextureNuclear);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

			glTranslatef(0.0, height, 0.0);
			glRotatef(-90, 1.0, 0.0, 0.0);
			gluDisk(quad, 0.0, outerRadius, 30.0, 3.0);
		glPopMatrix();
	glPopMatrix();
}

float Nuclear::getHeight()
{
	return height/2;
}

Nuclear::~Nuclear(void)
{
	gluDeleteQuadric(quad);
}
